﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MethodWorx.CMS.Linq
{
    public class GenericStorageEnumerator<T> : IEnumerator<T>
        where T : class
    {
        private IEnumerator<LinqGenericStorage> storage;
        private int current = -1;

        public GenericStorageEnumerator(IEnumerator<LinqGenericStorage> storage)
        {
            if (storage == null)
                throw new ArgumentNullException("storage");

            this.storage = storage;
        }
        #region IEnumerator<T> Members

        public T Current
        {
            get
            {
                return (T)this.storage.Current.ObjectStorage.Base64DeserializeUsingXml<T>();
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            this.storage.Dispose();
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get
            {
                return (object)this.storage.Current.ObjectStorage.Base64DeserializeUsingXml<T>();
            }
        }

        public bool MoveNext()
        {
            return this.storage.MoveNext();
        }

        public void Reset()
        {
            this.storage.Reset();

        }

        #endregion
    }
}
